<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Hash;

class AdminController extends Controller
{
    //
    public function index()
    {
    	// echo 22;
    	return view('admin.index');
    }

    public function login()
    {
    	return view('admin.login');
    }

    public function dologin(Request $request)
    {
    	// dd(222);
    	$data = $request->only(['username','password']);
    	// dd($data);
    	//检索数据库
    	$info = DB::table('users')->where('username',$data['username'])->first();
    	
    	//检测数据是否为空
    	if(empty($info)) {
    		return back()->with('info','用户名不存在!!!');
    	}
    	//检测密码
    	if(Hash::check($data['password'], $info->password)) {
    		//提醒
    		session(['uid'=>$info->id]);//
    		return redirect('/admin');
    	}else{
    		return back()->with('info','密码错误');
    	}
    }

    public function logout(Request $request)
    {
    	// dd(222);
    	$request->session()->forget('uid');
    	// session(['uid'=>null]);
    	return redirect('/admin');
    }
   
}
